#ifndef SERVERMANAGER_H
#define SERVERMANAGER_H

#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMap>
#include <QVector>
#include "clienthandler.h"

class ServerManager : public QObject
{
    Q_OBJECT
public:
    explicit ServerManager(QString hostAddress, quint16 port, QObject *parent = nullptr);
    void startServer();
private:
    QTcpServer* server = nullptr;
    QHostAddress listenIp;
    quint16 listenPort;
    QMap<QTcpSocket*,clientHandler*> clienthandlers;
    QMap<QTcpSocket*, QString> userOnlineList;
    QMap<QString, QTcpSocket*> usersMap;
    QVector<bool> meetingState;
    QVector<QStringList> meetingList;

private slots:
    void onNewConnection();
    void onUserOnline(QString name, QTcpSocket *socket);
    void onGetOnlineUsers();
    void onDisconnected();
    void onPrivateChat(messagePackage pack);
    void onGroupChat(messagePackage pack);
    void onInviteGroup(messagePackage pack);
    void onAddGroup(QStringList users, QString groupName, QString sender);
    void onGroupFile(messagePackage pack);
    void onMeeting(messagePackage pack);
    void onInviteMeeting(messagePackage pack);
    void onUpdateMeeting(messagePackage prevPack);
    void onQuitMeeting(messagePackage prevPack);
    void onClearMeeting(messagePackage prevPack);

signals:
    void clientConnected(QString ip,int port);
};

#endif // SERVERMANAGER_H
